package com.example.sb.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.connection.RedisZSetCommands;
import org.springframework.data.redis.core.*;
import org.springframework.data.redis.core.script.DefaultRedisScript;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.IntStream;

/**
 * @author kedong.lin
 */
@RestController
@RequestMapping("/redis")
public class RedisController {
    @Autowired
    private RedisTemplate redisTemplate;

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @RequestMapping("/test")
    public void testRedis() {
        String lua = "return 'hello redis'";
        DefaultRedisScript script = new DefaultRedisScript();
        script.setScriptText(lua);
        script.setResultType(String.class);
        String str = (String) redisTemplate.execute(script, redisTemplate.getStringSerializer(), redisTemplate.getStringSerializer(), null);
        System.out.println(str);

    }

}
